<script type="text/javascript">
  Zepto(function($){

<!-- <script type="text/javascript">
  var _arr = Array(), cur_window = '', reg_mobile = '',wait = 60, is_send = false,json_item_info = '',find_mobile='';
  $(function(){
      $('.btn-login').on('click', doLogin);
      $('.reg-btn').on('click', function(){
          cur_window = 'register';
          $('.login,.resetpwd').hide();
          $('.register').show(); 
      });
      $('.login-btn').on('click', function(){
          $('.login').show();
          $('.register,.resetpwd').hide();
      });
      $('.close').on('click', function(){ 
          cur_window = '';
          is_send = false;
          $('#login,#register,#resetpwd,.class-dialog,.course-ad').hide();
           
      });

      $('.reg-mobile').on('keyup', function(){
          reg_mobile = $('.reg-mobile').val();
          if(validateMobile(reg_mobile)) {
            $('.register').find('.flag').addClass('hf-dtm-get');
          }else $('.register').find('.flag').removeClass('hf-dtm-get');

      })

      $('.find_mobile').on('keyup', function(){
          find_mobile = $('.find_mobile').val();
          if(validateMobile(find_mobile)) {
            $('.resetpwd').find('.flag').addClass('hf-dtm-get');
          }else $('.resetpwd').find('.flag').removeClass('hf-dtm-get');

      })

      $('.find-pwd').on('click', function(){
          cur_window = 'resetpwd';
          $('.login,.register').hide();
          $('#resetpwd').show();
      });

      $('.register,.resetpwd').on('click', 'span.hf-dtm-get', getCode);
      $('.btn-register').on('click', Register);

  })

  function getCode(){
      if( !is_send ){
        var mobile ='';
        if( cur_window == 'resetpwd' ) mobile = find_mobile;
        else mobile = reg_mobile;
        $.post('/mobile/user.php?act=send_code', {'phone':mobile}, function(data){
            var data = jsonToArray(data);
            console.info(data.status);
            if( data.status != 'ok' ) {
                $('.'+cur_window).find('.code-error').text('验证码发送失败').show();
            }else{
                time( $('.'+cur_window).find(".hf-dtm-get" ));
            }
        })
      }

  }

  function Register(){
      var reg_code = $('.reg-code').val();
      var reg_pwd = $('.reg-pwd').val();
      var reg_name = $('.reg-name').val();
      if(!validateMobile(reg_mobile)){
          $('.reg-mobile-error > em').text('请输入正确的手机号').show();
          return;
      }
      if(!reg_name){
          $('.reg-name-error > em').text('请输入姓名').show();
          return;
      }
      if(!reg_pwd){
          $('.reg-pwd-error > em').text('请输入密码').show();
          return;
      }

      if( reg_pwd.length < 6 || reg_pwd.length > 20 ){
          $('.reg-pwd-error > em').text('密码长度6到20位').show();
          return;
      }

      $.post('/mobile/user.php?act=act_register', {'phone':reg_mobile,'pwd':reg_pwd,'username':reg_name,'code':reg_code,'item':json_item_info}, function(data){
          var reg_data = jsonToArray(data);
          var cur_path = window.location.href;
          if( reg_data.status != 'ok' ) {
              if( reg_data.type == 'isexist' ) {
                  $('.reg-mobile-error > em').text(reg_data.error).show();
                  return;
              }else if( reg_data.type == 'code_error' ){
                  $('.reg-code-error > em').text(reg_data.error).show();
                  return;
              }else if( reg_data.type == 'reg_error' ){
                  $('.reg-error > em').text(reg_data.error).show();
                  return;
              }else{
                  $('.reg-error > em').text('网络异常，请重新提交').show();
                  return;
              }
          }else{
            if( cur_path.indexOf("/goods.php") > 0 ){
                location.href="/mobile/order.php?act=order_lise";
            }else{
                location.reload();
            }
          }
      })
  }

  function time( btn ) {
      if( wait == 0 ) {
          btn.text( "重发验证码" );
          wait = 60;
          is_send = false;
      }
      else {
          is_send = true;
          wait--;
          setTimeout( function() {
              time( btn );
          }, 1000 );
          btn.text( wait + "s后重发" );
      }
  }

  function validateMobile( phone ){
    var myreg = /^1[34578][0-9]{9}$/; 
    if(!myreg.test(phone)) return false; 
    else return true;
  }

  function doLogin(){
      var phone = $('.login-name').val(), pwd = $('.login-pwd').val();
      if( !phone ){ 
        $('.login-name-error > em').text('请输入手机号').show(); 
        return;
      }
      if( !pwd ){ 
        $('.login-pwd-error > em').text('请输入密码').show(); 
        return;
      }
      $('.login-name-error,.login-pwd-error').hide();
      $.post('/mobile/user.php?act=do_login', {'mobile':phone,'pwd':pwd,'item':json_item_info}, function(data){
          var login_data = jsonToArray(data);
          var cur_path = window.location.href;
          if( login_data.status == 'ok' ){
            if( cur_path.indexOf("/goods.php") > 0 ){
                location.href="/mobile/order.php?act=order_lise";
            }else{
                location.reload();
            }
              
          }else{
              if( login_data.type == 'no_user' ) $('.login-name-error > em').text(login_data.error).show();
              else $('.login-pwd-error > em').text(login_data.error).show();
          }
      })
  }

  function findPwd(){
      find_mobile = $('.find_mobile').val();
      if(!validateMobile(find_mobile)){
          $('.find-mobile-error > em').text('请输入正确的手机号').show();
          return;
      }

      $.post('/mobile/user.php?act=find_pwd', {'phone':find_mobile,'pwd':reg_pwd,'item':json_item_info}, function(data){
          var reg_data = jsonToArray(data);
          var cur_path = window.location.href;
          if( reg_data.status != 'ok' ) {
              if( reg_data.type == 'isexist' ) {
                  $('.find-mobile-error > em').text(reg_data.error).show();
                  return;
              }else if( reg_data.type == 'code_error' ){
                  $('.find-code-error > em').text(reg_data.error).show();
                  return;
              }else if( reg_data.type == 'reg_error' ){
                  $('.find-error > em').text(reg_data.error).show();
                  return;
              }else{
                  $('.find-error > em').text('网络异常，请重新提交').show();
                  return;
              }
          }else{
            if( cur_path.indexOf("/goods.php") > 0 ){
                location.href="/mobile/order.php?act=order_lise";
            }else{
                location.reload();
            }
          }
      })
  }

  function jsonToArray( obj ){
      JSON.parse(obj, function (key, value) { _arr[key] = value;});
      return _arr;
  }

</script> -->